#define PCRE_STATIC
#include <stdio.h>
#include <string.h>
#include "/usr/include/pcre.h"
#define OVECCOUNT 30
#define EBUFLEN 128
#define BUFLEN 1024
int main(int argc, char const *argv[])
{
    pcre *re;
    const char *error;
    int erroffset;
    int vector[OVECCOUNT];
    int rc, i;
    char src[] = "111<title>Hello World</title>222";
    char pattern[] = "<title>(.*)</(tit)le>";
    printf("Srting:%s\n", src);
    printf("Pattern: %s\n", pattern);

    re = pcre_compile(pattern, 0, &error, &erroffset, NULL);

    if(re == NULL)
    {
       printf("PCRE compilation failed at offset %d:%s\n",erroffset,error);
       return 1;
    }

    rc = pcre_exec(re,NULL,src,strlen(src),0,0,vector,OVECCOUNT);

    if(rc<0){
    	if(rc==PCRE_ERROR_NOMATCH){
    		printf("Sorry , no match.....\n");
    	}
    	else{
    		printf("Matching error %d\n", rc );
    	}
    	pcre_free(re);
    	return 1;
    }
    printf("\n OK, has matched .....\n");
    for (int i = 0; i < rc; ++i)
    {
    	char *substring_start = src+vector[2*i];
    	int substring_length = vector[2*i+1]-vector[2*i];
    	printf("$-: %d  %.*s\n", i,substring_length, substring_start);
    }

    pcre_free(re);

    return 0;
}
